var i=0;//选项计数
var flag=true;//判断是否结束选择跳转
Page({
  data: {
    background2:"https://s4.ax1x.com/2021/12/05/oBXtgJ.png",
    button:"https://z3.ax1x.com/2021/11/29/oMXjnP.png",
    touchS : [0,0],//手动触摸屏幕位置
    touchE : [0,0],//
    move:0,//判断手动移动
    animationData:[],
    count:0,//点击计数
    donghua:true,
   // isChecked:true,
    touchDonghua:'',
    arr:[//选择数组
      {
        id:0,
        txt:"早睡早起",
        icon:"https://s4.ax1x.com/2021/12/05/oDSFfK.png",
        top:430,
        donghua:"animationData0",
        clickIt:false,
      },
      {
        id:1,
        txt:"每天保持运动",
        icon:"https://s4.ax1x.com/2021/12/05/oDFgBD.png",
        top:600,
        donghua:"animationData1",
        clickIt:false,
      },
      {
        id:2,
        txt:"学会控制情绪",
        icon:"https://s4.ax1x.com/2021/12/05/oDFqHg.png",
        top:790,
        donghua:"animationData2",
        clickIt:false,
        
      },
      {
        id:3,
        txt:"注意个人卫生",
        icon:"https://s4.ax1x.com/2021/12/05/oDFTjf.png",
        top:480,
        donghua:"animationData3",
        clickIt:false,
      },
      {
        id:4,
        txt:"光盘行动",
        icon:"https://s4.ax1x.com/2021/12/05/oDkdr8.png",
        top:610,
        donghua:"animationData4",
        clickIt:false,
      
      },
      {
        id:5,
        txt:"送自己一份礼物",
        icon:"https://s4.ax1x.com/2021/12/05/oDAUY9.png",
        top:820,
        donghua:"animationData5",
        clickIt:false,
      
      },
      {
        id:6,
        txt:"去来一场旅行",
        icon:"https://s4.ax1x.com/2021/12/05/oDQFhT.png",
        top:430,
        donghua:"animationData6",
        clickIt:false,
      },
      {
        id:7,
        txt:"学一个技能",
        icon:"https://s4.ax1x.com/2021/12/05/oDQmu9.png",
        top:610,
        donghua:"animationData7",
        clickIt:false,
      },
      {
        id:8,
        txt:"帮忙做一次家务",
        icon:"https://s4.ax1x.com/2021/12/05/oDQDC8.png",
        top:850,
        donghua:"animationData8",
        clickIt:false,
      },
      {
        id:9,
        txt:"拍一次全家福",
        icon:"https://s4.ax1x.com/2021/12/05/oDQWEq.png",
        top:430,
        donghua:"animationData9",
        clickIt:false,
      },
      {
        id:10,
        txt:"为家人做一顿饭",
        icon:"https://s4.ax1x.com/2021/12/05/oDQmu9.png",
        top:680,
        donghua:"animationData10",
        clickIt:false,
      },
      {
        id:11,
        txt:"和家人去看一场电影",
        icon:"https://s4.ax1x.com/2021/12/05/oDQ2bn.png",
        top:850,
        donghua:"animationData11",
        clickIt:false,
      }
      ,
      {
        id:12,
        txt:"认真倾听他人",
        icon:"https://s4.ax1x.com/2021/12/05/oDQqbR.png",
        top:430,
        donghua:"animationData12",
        clickIt:false,
      },
      {
        id:13,
        txt:"遇到老师同学主动问好",
        icon:"https://s4.ax1x.com/2021/12/05/oDQTv4.png",
        top:650,
        donghua:"animationData13",
        clickIt:false,
      },
      {
        id:14,
        txt:"课前帮老师擦黑板",
        icon:"https://s4.ax1x.com/2021/12/05/oDQHKJ.png",
        top:840,
        donghua:"animationData14",
        clickIt:false,
      },
      {
        id:15,
        txt:"体验一次友善课堂",
        icon:"https://s4.ax1x.com/2021/12/05/oDQNDA.png",
        top:430,
        donghua:"animationData15",
        clickIt:false,
      },
      {
        id:16,
        txt:"帮朋友取一次快递",
        icon:"https://s4.ax1x.com/2021/12/05/oD62UP.png",
        top:560,
        donghua:"animationData16",
        clickIt:false,
      },
      {
        id:17,
        txt:"相约橘子洲头看烟花",
        icon:"https://s4.ax1x.com/2021/12/05/oD64gg.png",
        top:790,
        donghua:"animationData17",
        clickIt:false,
      },
      {
        id:18,
        txt:"及时回复信息",
        icon:"https://s4.ax1x.com/2021/12/05/oDQOV1.png",
        top:430,
        donghua:"animationData18",
        clickIt:false,
      },
      {
        id:19,
        txt:"对着镜子里的自己微笑",
        icon:"https://s4.ax1x.com/2021/12/05/oDQwUP.png",
        top:590,
        donghua:"animationData19",
        clickIt:false,
      },
      {
        id:20,
        txt:"准时赴约不迟到",
        icon:"https://s4.ax1x.com/2021/12/05/oDctMQ.png",
        top:820,
        donghua:"animationData20",
        clickIt:false,
      },
      {
        id:21,
        txt:"做老师的小助手",
        icon:"https://s4.ax1x.com/2021/12/05/oDQI8U.png",
        top:430,
        donghua:"animationData21",
        clickIt:false,
      },
      {
        id:22,
        txt:"献一次血",
        icon:"https://s4.ax1x.com/2021/12/05/oDcNrj.png",
        top:600,
        donghua:"animationData22",
        clickIt:false,
      },
      {
        id:23,
        txt:"主动给家人打一次电话",
        icon:"https://s4.ax1x.com/2021/12/05/oDQsgg.png",
        top:790,
        donghua:"animationData23",
        clickIt:false,
      },
      {
        id:24,
        txt:"遵守交通规则",
        icon:"https://s4.ax1x.com/2021/12/05/oDgd6e.png",
        top:430,
        donghua:"animationData24",
        clickIt:false,
      },
      {
        id:25,
        txt:"种一棵树",
        icon:"https://s4.ax1x.com/2021/12/05/oDgalD.png",
        top:670,
        donghua:"animationData25",
        clickIt:false,
      },
      {
        id:26,
        txt:"疫情期间自觉戴好口罩",
        icon:"https://s4.ax1x.com/2021/12/05/oDcUqs.png",
        top:840,
        donghua:"animationData26",
        clickIt:false,
      },
      {
        id:27,
        txt:"常回家看看",
        icon:"https://s4.ax1x.com/2021/12/05/oDQgDs.png",
        top:430,
        donghua:"animationData27",
        clickIt:false,
      },
      {
        id:28,
        txt:"共享单车放到指定位置",
        icon:"https://s4.ax1x.com/2021/12/05/oDgrTI.png",
        top:650,
        donghua:"animationData28",
        clickIt:false,
      },
      {
        id:29,
        txt:"主动扶起倒地的单车",
        icon:"https://s4.ax1x.com/2021/12/05/oDgUSO.png",
        top:850,
        donghua:"animationData29",
        clickIt:false,
      },
      {
        id:30,
        txt:"上课认真听讲",
        icon:"https://s4.ax1x.com/2021/12/05/oDQo2F.png",
        top:430,
        donghua:"animationData30",
        clickIt:false,
      },
      {
        id:31,
        txt:"吃一顿大餐",
        icon:"https://s4.ax1x.com/2021/12/05/oDQ5CT.png",
        top:650,
        donghua:"animationData31",
        clickIt:false,
      },
      {
        id:32,
        txt:"和家人一起去旅行",
        icon:"https://s4.ax1x.com/2021/12/05/oDQfU0.png",
        top:850,
        donghua:"animationData32",
        clickIt:false,
      },
      {
        id:33,
        txt:"参与一次公益捐助活动",
        icon:"https://s4.ax1x.com/2021/12/05/oDQDC8.png",
        top:430,
        donghua:"animationData33",
        clickIt:false,
      },
      {
        id:34,
        txt:"帮助别人答疑解惑",
        icon:"https://s4.ax1x.com/2021/12/05/oDQl4K.png",
        top:620,
        donghua:"animationData34",
        clickIt:false,
      },
      {
        id:35,
        txt:"和朋友一起看天鹅",
        icon:"https://s4.ax1x.com/2021/12/05/oDcJxg.png",
        top:820,
        donghua:"animationData35",
        clickIt:false,
      },
      {
        id:36,
        txt:"救助流浪动物",
        icon:"https://s4.ax1x.com/2021/12/05/oDgD0A.png",
        top:460,
        donghua:"animationData36",
        clickIt:false,
      },
      {
        id:37,
        txt:"爱护花草树木",
        icon:"https://s4.ax1x.com/2021/12/05/oDc3Pf.png",
        top:650,
        donghua:"animationData37",
        clickIt:false,
      },
      {
        id:38,
        txt:"和家人去看一场电影",
        icon:"https://s4.ax1x.com/2021/12/05/oDQfU0.png",
        top:820,
        donghua:"animationData38",
        clickIt:false,
      },
      {
        id:39,
        txt:"认识一种保护动植物",
        icon:"https://s4.ax1x.com/2021/12/05/oDgBmd.png",
        top:440,
        donghua:"animationData39",
        clickIt:false,
      },
      {
        id:40,
        txt:"进行垃圾分类",
        icon:"https://s4.ax1x.com/2021/12/05/oDgwOH.png",
        top:550,
        donghua:"animationData40",
        clickIt:false,
      },
    ],

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.donghua()
  },
  donghua:function(){
    let that=this;
     let animationData=this.data.animationData
     const animation =wx.createAnimation({
       delay: 0,
      //  duration:8000,
     })
    this.animation=animation
    setTimeout(function(){
        animation.translate(-800).step({duration:8000});
      animationData[i]=animation.export()
    //  // console.log(animationData[i])
      this.setData({
        animationData:animationData
      })
      i++;
    }.bind(this),0)
    if(i%3==0&&flag){//四个选项一列
     setTimeout(function(){
             this.donghua()
           }.bind(this),1400)
    }else if(flag){
         setTimeout(function(){
        this.donghua()//递归来循环
      }.bind(this),500)
    }else{
     console.log("结束")
        setTimeout(function(){
          this.setData({
            donghua:false
          })
        }.bind(this),4500)
    }

  },
  //点击函数
  click:function(e){
    let that=this;
  //  let arr=this.data.arr; 
    var dataset = e.target.dataset;
  //  console.log(e.target.dataset.index)
    var index= dataset.index;
    if(this.data.arr[index].clickIt==true)
    {
      this.data.arr[index].clickIt=false;
      this.setData({
        count:this.data.count-1,
        arr:this.data.arr
      })
    }
    else{
      this.data.arr[index].clickIt=true;
      this.setData({
        count:this.data.count+1,
        arr:this.data.arr
      })
    }
    console.log(this.data.arr[index])
  },
  sendData:function(){
    var that=this;
    flag=false;
    getApp().globalData.choiceAnswerNow = that.data.arr;
    // getApp().globalData.clickNum=that.data.count;
  },
  // 触摸开始事件
  touchStart: function(e){
     console.log(e.touches[0].pageX)
    let sx = e.touches[0].pageX
    let sy = e.touches[0].pageY
    this.data.touchS = [sx,sy]
  },
  // 触摸滑动事件
  touchMove: function(e){
    let sx = e.touches[0].pageX;
    let sy = e.touches[0].pageY;
    this.data.touchE = [sx, sy];
  },
  // 触摸结束事件
  touchEnd: function(e){
    let start = this.data.touchS
    let end = this.data.touchE
    // console.log(start)
    // console.log(end)
    if(start[0] < end[0] - 50){
      console.log('向右滑，这里可以调用方法，及页面跳转事件')
      this.setData({
        move:50
      //  touchDonghua:'-webkit-animation: move 0.4s linear;animation:move 0.4s linear;'
      })
    }else if(start[0] > end[0] + 50){
      // console.log('向左滑，这里可以调用方法，及页面跳转事件')
      this.setData({
        move:-50
      })
    }else{
      // console.log('向上或向下滑动')
    }
  },

})